package com.easy.user.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.easy.bean.Address;
import com.easy.bean.Users;
import com.easy.user.service.IUserService;
import com.easy.user.util.JWTUtil;

@RestController
@RequestMapping("user/feign")
@CrossOrigin
public class EasyFeignUserController {
    @Autowired
    IUserService userS;

    @RequestMapping(method = RequestMethod.GET,path = "address/{id}")
    public Address getAddress(@PathVariable int id){
       return  userS.getAddress(id);
    }

    @GetMapping("/loginuser/{token}")
    public Users loginUser(@PathVariable String token) {
        //通过token获取登录用户userid
        System.out.println(token);
        Integer id = JWTUtil.userid(token);
        System.out.println(id);
        //查询该用户的信息--- 嵌入redis
        Users user = userS.getUsersByID(id);
        System.out.println(user);
        user.setPassword(null);
        return user;
    }
}
